blob: 32924d031c8e151b352de4456a3f2d30eff1b763 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import { fd, auth, get, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
export const load = async ({ params: { id } }) => {
const item = await get(`/items/${id}`);
return { item };
};
export const actions = {
default: async ({ cookies, request, url }) => {
const form = await fd(request);
try {
await post("/items", form, auth(cookies));
} catch (e: any) {
return fail(400, { message: e.message });
}
const success = `/${url.pathname.split("/")[1]}`;
redirect(307, success);
},
};
|